package com.supreme.proxyserver.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.supreme.commonmybatis.mapper.UserMapper;
import com.supreme.commonmybatis.entity.mbpmap.AuthUser;
import com.supreme.commonmybatis.entity.mbpmap.BizUser;
import com.supreme.commonentity.mysql.primary.SysUser;
import com.supreme.commonboot.utils.AjaxResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "user")
public class UserController {

    private final UserMapper userMapper;

    @Autowired
    public UserController(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @GetMapping(value = "search")
    public AjaxResp searchUser() {
        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
        List<SysUser> userList = this.userMapper.selectList(queryWrapper);
        return new AjaxResp(userList);
    }

    @GetMapping(value = "authUser")
    public AjaxResp getAuthUser(@RequestParam(value = "username") String username,
                                @RequestParam(value = "password") String password) {
        AuthUser authUser = this.userMapper.selectAuthUser(username, password);
        return new AjaxResp(authUser);
    }

    @GetMapping(value = "userBizInfo")
    public AjaxResp getUserBizInfo(@RequestParam(value = "userId") Long userId) {
        BizUser bizUser = this.userMapper.selectUserBizInfo(userId);
        return new AjaxResp(bizUser);
    }

    @GetMapping(value = "userBizInfo2")
    public AjaxResp getUserBizInfo2(@RequestParam(value = "userId") Long userId) {
        BizUser bizUser = this.userMapper.selectUserBizInfo2(userId);
        return new AjaxResp().setData(bizUser);
    }
}
